home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3263 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.7 KB  |  55 lines

  1. Path: news.pge.com!usenet
  2. From: psk3@pge.com (Phillip Knight)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: overiding c++ stream classes anyone?
  5. Date: 23 Jan 1996 02:38:56 GMT
  6. Organization: Pacific Gas and Electric
  7. Message-ID: <4e1ho0$5en@news02.comp.pge.com>
  8. References: <4cqbja$62n@earth.njcc.com> <4e1d5f$5en@news02.comp.pge.com>
  9. NNTP-Posting-Host: psk3ws04.comp.pge.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.6
  13.  
  14. In article <4e1d5f$5en@news02.comp.pge.com>, psk3@pge.comâ–Œ says...
  15. >
  16. >I have pulled the last hair out of my head and still have not solved this 
  17. >problem:
  18. >
  19. >        class X : public ostream {
  20. >        public:
  21. >        ...
  22. >        X& operator<<(X& (*f)(X&)) { return (*f)(*this); }
  23. >        };
  24. >
  25. >
  26. >        X& newl(X& os) {
  27. >                cerr << "this never gets printed" << endl;
  28. >        }
  29. >
  30. >        main() {
  31. >           X foo;
  32. >           foo << "test one";
  33. >           foo << endl;
  34. >
  35. >           foo << "test two" << endl;
  36. >        }
  37. >
  38. >so the problem is simple: how do i get my manipulator newl to be called?  This 
  39. >program as stands does not compile, because inclusion of the operator '<<' 
  40. >(used in order to execute the manipulator) causes class X to no longer 
  41. >recognize the base class operators (it only recognizes X's operator <<).  
  42. >taking the operator out of the class and into the code as a function doesn't 
  43. >solve the problem either as newl never gets called.
  44. >
  45.  
  46. well, i got this to work using a friend, but the question still remains:  why 
  47. does declaring any type of "operator<<" cause the base classes operators to be 
  48. effectivily hidden?  not that i need to do this anymore, but just wondering...
  49.  
  50. thanks again!
  51. Phil Knight
  52. psk3@pge.com
  53. >
  54.  
  55.